import QtQuick

Window {
    id: myWindow
    width: 300
    height: 300
    visible: true

    Component.onCompleted: {
        // 定义 QML 字符串
        var qmlString = `
            import QtQuick
            Rectangle {
                width: 100
                height: 100
                color: "orange"
            }
        `;

        // 直接从 QML 字符串创建对象
        var rect = Qt.createQmlObject(qmlString, myWindow, "dynamicObject");

        // 设置对象位置
        rect.x = 100;
        rect.y = 100;
    }
}
